package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.HisContractEntity;
import io.renren.service.HisContractService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 历史合同基础表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-06-12 10:12:18
 */
@Controller
@RequestMapping("hiscontract")
public class HisContractController {
	@Autowired
	private HisContractService hisContractService;
	
	@RequestMapping("/hiscontract.html")
	public String list(){
		return "hiscontract/hiscontract.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("hiscontract:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<HisContractEntity> hisContractList = hisContractService.queryList(map);
		int total = hisContractService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(hisContractList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("hiscontract:info")
	public R info(@PathVariable("id") String id){
		HisContractEntity hisContract = hisContractService.queryObject(id);
		
		return R.ok().put("hisContract", hisContract);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("hiscontract:save")
	public R save(@RequestBody HisContractEntity hisContract){
		hisContractService.save(hisContract);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("hiscontract:update")
	public R update(@RequestBody HisContractEntity hisContract){
		hisContractService.update(hisContract);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("hiscontract:delete")
	public R delete(@RequestBody String[] ids){
		hisContractService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
